<?php
if(!interface_exists('XCookie', false)){
	require_once(XFRAMEWORK_DIR.'/core/mvc/http/XCookie.php');
}
class XServletCookie implements XCookie{
	private static $instance = null;
	private $name = null;
	private $value = null;
	private $expire = null;
	private $path = null;
	private $domain = null;
	private $secure = null;
	private $httpOnly = null;
	
	private function __construct(){
		
	}

	/** 
	 * @return XServletCookie
	 */		
	static function singleton() {
		if (!self::$instance) {
			self::$instance = new self;
		}
		return self::$instance;
	}

	public function setCookie(){
		return setcookie($this->name, $this->value, $this->expire, $this->path, $this->domain, $this->secure, $this->httpOnly);
	}
	
	public function set($key, $value, $age = 0){
		return setcookie($key, $value, $age, $this->path, $this->domain, $this->secure, $this->httpOnly);
	}
	
	/** 
	 * @return mixed
	 */	
	public function get($key){
		return x_array_get($_COOKIE, $key);
	}
	
	/** 
	 * @return array
	 */		
	public function getAll(){
		return $_COOKIE;
	}
		
	/**
	 * @return string
	 */
	public function getName() {
		return $this->name;
	}

	/**
	 * @return string
	 */
	public function getValue() {
		return $this->value;
	}

	/**
	 * @return int
	 */
	public function getExpire() {
		return $this->expire;
	}

	/**
	 * @return string
	 */
	public function getPath() {
		return $this->path;
	}

	/**
	 * @return string
	 */
	public function getDomain() {
		return $this->domain;
	}

	/**
	 * @return string
	 */
	public function getSecure() {
		return $this->secure;
	}

	/**
	 * @return int
	 */
	public function getHttpOnly() {
		return $this->httpOnly;
	}

	/**
	 * @return XServletCookie
	 */
	public function setName($name) {
		$this->name = $name;
		return $this;
	}

	/**
	 * @return XServletCookie
	 */
	public function setValue($value) {
		$this->value = $value;
		return $this;
	}

	/**
	 * @return XServletCookie
	 */
	public function setExpire($expire) {
		$this->expire = $expire;
		return $this;
	}

	/**
	 * @return XServletCookie
	 */
	public function setPath($path) {
		$this->path = $path;
		return $this;
	}

	/**
	 * @return XServletCookie
	 */
	public function setDomain($domain) {
		$this->domain = $domain;
		return $this;
	}

	/**
	 * @return XServletCookie
	 */
	public function setSecure($secure) {
		$this->secure = $secure;
		return $this;
	}

	/**
	 * @return XServletCookie
	 */
	public function setHttpOnly($httpOnly) {
		$this->httpOnly = $httpOnly;
		return $this;
	}
}
?>